<?php
namespace app\admin\controller;
use think\Controller;

class Bis extends Controller  //控制器层
{
    //构造函数 私有属性
	private $obj;
	public function _initialize(){
		$this->obj = model("Bis");
		}
	
	//入驻申请
	public function apply()
    {
        $bis = $this ->obj->getBisByStatus();
		return $this->fetch('', [
		    'bis' => $bis,
		]);
	}
	
	
	//商户列表
	public function index()
    {
        $bis = $this ->obj->getBisByStatus(1);
		return $this->fetch('', [
		    'bis' => $bis,
		]);
	}
	
	public function detail(){
		$id = input('get.id');
		if(empty($id)){
			return $this->error('ID错误');
			}
		
		
		//获取一级城市数据
		$citys = model('City')->getNormalCitysByParentId();
		
		//获取一级分类数据
		$categorys = model('Category')->getNormalCategorysByParentId();
		//获取商户数据
		$bisData = model('Bis')->get($id);
		$locationData = model('BisLocation')->get(['bis_id'=>$id,'is_main'=>1]);
		$accountData = model('BisAccount')->get(['bis_id'=>$id,'is_main'=>1]);
		
		return $this->fetch('',[
		    'citys' => $citys,
			'categorys' => $categorys,
			'bisData' => $bisData,
			'locationData' => $locationData,
			'accountData' => $accountData,
		]);	

		
		}
	
	
	public function dellist()
    {
      
		$bis = $this ->obj->getBisByStatus(-1);
		//halt($bis);
		return $this->fetch('', [
		    'bis' => $bis,
		]);
	}
	
	public function notpass()
    {
      
		$bis = $this ->obj->getBisByStatus(2);
		//halt($bis);
		return $this->fetch('', [
		    'bis' => $bis,
		]);
	}
	
	
	
	
	
	
	
	
	
	
	
	
	//修改状态
	public function status(){
		// print_r(input('get.'));
		$data = input('get.');
		/* $validate=validate('Bis');
		 if(!$validate->scene('status')->check($data)){
			 $this->error($validate->getError()); 
			 }  */
		 
		 $res = $this->obj->save(['status'=>$data['status']], 
		     ['id'=>$data['id']]);
		$location = model('BisLocation')->save(['status'=>$data['status']], 
		     ['bis_id'=>$data['id']],
			 ['is_main'=>1]);
		$account = model('BisAccount')->save(['status'=>$data['status']], 
		     ['bis_id'=>$data['id']], ['is_main'=>1]);
		 if($res /* && $location && $account  */){
			 //发送邮件
			 
			//   \phpmailer\Email::send($data['email'], $title, $content);
			 
			 $this->success('状态更新成功');
			 }else{
				$this->error('状态更新失败');
				 }
		 
		}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
?>